Imported Upstream version 1.0.4
authorAron Xu <aron@debian.org>
Mon, 8 Aug 2016 06:36:18 +0000 (14:36 +0800)
committerAron Xu <aron@debian.org>
Mon, 8 Aug 2016 06:36:18 +0000 (14:36 +0800)
22 files changed:
CMakeLists.txt
Makefile
NEWS.md
README.md
data/dictionary/HKVariants.txt
data/dictionary/STCharacters.txt
data/dictionary/TSCharacters.txt
data/dictionary/TWPhrasesIT.txt
data/dictionary/TWPhrasesName.txt
data/scripts/find_target.py
data/scripts/merge.py
data/scripts/reverse.py
data/scripts/sort.py
data/scripts/sort_all.py
node/binding.cc
node/global.gypi
package.json
src/Config.cpp
src/SerializableDict.hpp
src/SimpleConverter.cpp
src/UTF8Util.hpp
src/opencc.h

index a0c37476237ec05cac17a6a202b934db6f9ba1a9..5ff33eb0711eb73b979053830d798c5038412d2e 100644 (file)
@@ -32,7 +32,7 @@ set (PACKAGE_URL https://github.com/BYVoid/Opencc)
 set (PACKAGE_BUGREPORT https://github.com/BYVoid/Opencc/issues)
 set (OPENCC_VERSION_MAJOR 1)
 set (OPENCC_VERSION_MINOR 0)
-set (OPENCC_VERSION_REVISION 3)
+set (OPENCC_VERSION_REVISION 4)
 
 if (CMAKE_BUILD_TYPE MATCHES Debug)
   set (version_suffix .Debug)
index 297e0296682e1bd9fd9bf96a2fd1a7efc217b11b..25d7c64fe3eb1a51f5a92109dd18f14396d7e1a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,8 @@
 # limitations under the License.
 #
 
+PREFIX = /usr
+
 .PHONY: build clean node test xcode-build
 
 build:
@@ -24,12 +26,13 @@ build:
        -DBUILD_DOCUMENTATION:BOOL=ON \
        -DENABLE_GTEST:BOOL=OFF \
        -DCMAKE_BUILD_TYPE=Release \
-       -DCMAKE_INSTALL_PREFIX=/usr \
+       -DCMAKE_INSTALL_PREFIX=${PREFIX} \
        ../..)
-       make -C build/rel VERBOSE=${VERBOSE}
+       make -C build/rel VERBOSE=${VERBOSE} PREFIX=${PREFIX}
 
 package: build
        make -C build/rel package_source VERBOSE=${VERBOSE}
+       make -C build/rel package_source VERBOSE=${VERBOSE} PREFIX=${PREFIX}
 
 test:
        mkdir -p build/dbg/root
@@ -65,4 +68,4 @@ clean:
        rm -rf build xcode
 
 install: build
-       make -C build/rel install VERBOSE=${VERBOSE}
+       make -C build/rel install VERBOSE=${VERBOSE} PREFIX=${PREFIX}
diff --git a/NEWS.md b/NEWS.md
index 8fd420a37d3510ac23bc1852b9d20566894a7d9b..90553e414b3b3c1fd87cd96b0b1a1b26959fe4ae 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,14 @@
 # Change History of OpenCC
 
+## Version 1.0.4
+
+2016年4月1日
+
+* 使編譯時的腳本兼容Python 3。
+* 修正Visual C++ 2015的編譯問題。
+* 增補臺灣、香港地區用字用詞轉換。
+* 更新nan以修正Node.js擴展編譯兼容性問題。
+
 ## Version 1.0.3
 
 2015年7月22日
index 18de2d2c38184165e9d910502742cce93bba5714..1ff2e917d46b510d3ef191b924975b3d210946b7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for c
 * 嚴格審校一簡對多繁詞條,原則爲「能分則不合」。
 * 支持中國大陸、臺灣、香港異體字和地區習慣用詞轉換,如「裏」「裡」、「鼠標」「滑鼠」。
 * 詞庫和函數庫完全分離,可以自由修改、導入、擴展。
-* 支持C、C++、Python、PHP、Java、Ruby、Node.js。
+* 支持C、C++、Python、PHP、Java、Ruby、Node.js and Android
 * 兼容Windows、Linux、Mac平臺。
 
 ### Links 相關鏈接
@@ -66,13 +66,20 @@ https://bintray.com/byvoid/opencc/OpenCC
 
 ### Build with CMake
 
-Linux/OSX (gcc 4.6 or clang 3.2 is required):
+Linux (gcc 4.6 is required):
 
 ```
 make
 sudo make install
 ```
 
+Mac OS X (clang 3.2 is required):
+
+```
+make PREFIX=/usr/local
+sudo make PREFIX=/usr/local install
+```
+
 Windows MSYS:
 
 ```
@@ -87,7 +94,15 @@ cmake .. -G "Visual Studio 12" -DCMAKE_INSTALL_PREFIX="" -DCMAKE_BUILD_TYPE=Rele
 make
 ```
 
-### Projects using Opencc 使用OpenCC的項目
+### iOS
+
+See https://github.com/gelosie/OpenCC/tree/master/iOS
+
+### Android
+
+See [android-opencc](https://github.com/qichuan/android-opencc)
+
+## Projects using Opencc 使用OpenCC的項目
 
 * [ibus-pinyin](http://code.google.com/p/ibus/)
 * [fcitx](http://code.google.com/p/fcitx/)
@@ -96,6 +111,8 @@ make
 * [ibus-libpinyin](https://github.com/libpinyin/ibus-libpinyin)
 * [BYVBlog](https://github.com/byvoid/byvblog)
 * [豆瓣同城微信](http://weixinqiao.com/douban-event/)
+* [alfred-chinese-converter](https://github.com/amowu/alfred-chinese-converter)
+* [GoldenDict](https://github.com/goldendict/goldendict)
 
 ## License 許可協議
 
@@ -109,6 +126,10 @@ Apache License 2.0
 
 All these libraries are statically linked.
 
+## Change History 版本歷史
+
+https://github.com/BYVoid/OpenCC/blob/master/NEWS.md
+
 ## Contributors 貢獻者
 
 * [BYVoid](http://www.byvoid.com/)
@@ -134,3 +155,15 @@ All these libraries are statically linked.
 * [吕旭东](https://github.com/lvxudong)
 * [Weng Xuetian](https://github.com/wengxt)
 * [Ma Tao](https://github.com/iwater)
+* [Heinz Wiesinger](https://github.com/pprkut)
+* [J.W](https://github.com/jakwings)
+* [Amo Wu](https://github.com/amowu)
+* [Mark Tsai](https://github.com/mxgit1090)
+* [Zhe Wang](https://github.com/0x1997)
+* [sgqy](https://github.com/sgqy)
+* [Qichuan (Sean) ZHANG](https://github.com/qichuan)
+* [Flandre Scarlet](https://github.com/XadillaX)
+* [宋辰文](https://github.com/songchenwen)
+* [iwater](https://github.com/iwater)
+
+Please update this list you have contributed OpenCC.
index 635ac2a227ffa5f06be83656252c932d1fa60938..2660bca59fef4f688fe5006a124736c1eac9e793 100644 (file)
@@ -48,6 +48,7 @@
 膃    腽
 臥    卧
 臺    台
+菸    煙
 蒕    蒀
 蔥    葱
 蔿    蒍
index 0183381688993d6a5b12ed2cd69ca457c40b2a7e..b937f526864b70cc62b8246a171f35ad119aaf67 100644 (file)
 龚    龔
 龛    龕
 龟    龜
+鿎    䃮
+鿏    䥑
+鿒    鿓
+鿔    鎶
 𠀾   𠁞
 𠆲   儣
 𠆿   𠌥
 𫠒   鱆
 𫠖   𩿅
 𫠜   齯
+𬬭   錀
+𬬻   鑪
+𬭊   𨧀
+𬭛   𨨏
+𬭳   𨭎
+𬭶   𨭆
index 9bc2f27077ca15178c865279c46a910fbe53a245..ef0629dc964b55a58ba87615995864d99dc5d9d8 100644 (file)
@@ -55,6 +55,7 @@
 䁪    𥇢
 䁻    䀥
 䂎    𥎝
+䃮    鿎
 䅐    𫀨
 䅳    𫀬
 䆉    𫁂
 䤤    𫟺
 䥄    𫠀
 䥇    䦂
+䥑    鿏
 䥗    𫔋
 䥩    𨱖
 䥯    𫔆
 鋶    锍
 鋸    锯
 鋼    钢
+錀    𬬭
 錁    锞
 錂    𨱋
 錄    录
 鎲    镋
 鎳    镍
 鎵    镓
+鎶    鿔
 鎷    𨰾
 鎸    镌
 鎿    镎
 鑠    铄
 鑣    镳
 鑥    镥
+鑪    𬬻
 鑭    镧
 鑰    钥
 鑱    镵
 龭    𩨎
 龯    𨱆
 鿁    䜤
+鿓    鿒
 𠁞   𠀾
 𠌥   𠆿
 𠏢   𠉗
 𨥛   𨱀
 𨥟   𫓫
 𨦫   䦀
+𨧀   𬭊
 𨧜   䦁
 𨧰   𫟽
 𨧱   𨱊
+𨨏   𬭛
 𨨛   𫓼
 𨨢   𫓿
 𨩰   𫟾
 𨪕   𫓮
 𨫒   𨱐
 𨬖   𫔏
+𨭆   𬭶
+𨭎   𬭳
 𨭖   𫔑
 𨭸   𫔐
 𨮂   𨱕
index 21f2c5bb92a9672b2d3f7c6f51bdc2cd70241830..47225685fd915ce56e36bd3caba01aa746020a9b 100644 (file)
@@ -46,12 +46,15 @@ SQL注入攻擊     SQL隱碼攻擊
 內核 核心
 內置 內建
 內聯函數   行內函數
+全局 全域性
 全角 全形
 兼容 相容
 冒泡排序   氣泡排序
+函數 函式
 函數式編程        函數語言程式設計
 刀片服務器        刀鋒伺服器
 分佈式      分散式
+分區 分割槽
 分辨率      解析度
 刷新 重新整理
 刻錄 燒錄
@@ -63,6 +66,8 @@ SQL注入攻擊       SQL隱碼攻擊
 半角 半形
 博客 部落格
 卸載 解除安裝
+原代碼      原始碼
+參數 引數
 參數表      參數列
 句柄 控制代碼
 可視化      視覺化
@@ -74,13 +79,15 @@ SQL注入攻擊     SQL隱碼攻擊
 哈希 雜湊
 單片機      微控制器
 回調 回撥
+固件 韌體
 圖像 影象
 圖庫 相簿
 圖標 圖示
 在線 線上
 地址 地址 位址
 地址欄      位址列
-城域王      都會網路
+城域網      都會網路
+堆棧 堆疊
 場效應管   場效電晶體
 壁紙 桌布 壁紙
 外置 外接
@@ -91,12 +98,15 @@ SQL注入攻擊     SQL隱碼攻擊
 字庫 字型檔
 字段 欄位
 字符 字元
+字符串      字串
 字符集      字符集
 字節 位元組
 字體 字型
 存儲 儲存
 存盤 存檔
+宏    巨集
 宏內核      單核心
+寄存器      暫存器
 密鑰 金鑰
 實例 例項 實例
 實模式      真實模式
@@ -109,9 +119,11 @@ SQL注入攻擊    SQL隱碼攻擊
 導入 匯入
 導出 匯出
 局域網      區域網
+局部 區域性
 屏幕 螢幕
 屏蔽 遮蔽
 嵌套 巢狀
+布爾 布林
 帶寬 頻寬
 引導程序   載入程式
 彙編 彙編 組譯
@@ -125,16 +137,19 @@ SQL注入攻擊   SQL隱碼攻擊
 打印 列印
 打印機      印表機
 打開 開啟 打開
+拋出 丟擲
 持久性      永續性
+指針 指標
 捲積 摺積
 掃描儀      掃描器
 掛斷 結束通話
 採樣 取樣
 採樣率      取樣率
 接口 介面
-控件 控制
+控件 控制元件
 插件 外掛
 搜索 搜尋
+操作數      運算元
 操作系統   作業系統
 擴展 擴充套件
 擴展名      副檔名
@@ -176,6 +191,7 @@ SQL注入攻擊     SQL隱碼攻擊
 查看 檢視
 桌面型      桌上型
 構造函數   建構函式
+標識符      識別符號
 模塊 模組
 模擬 模擬 類比
 模擬電子   類比電子
@@ -185,12 +201,14 @@ SQL注入攻擊   SQL隱碼攻擊
 死機 宕機
 殺毒 防毒
 比特 位元
+比特幣      比特幣
 比特率      位元率
 波分複用   波長分波多工
 消息 訊息 消息
 添加 新增
 源代碼      原始碼
 源文件      原始檔
+源碼 原始碼
 溢出 溢位
 演示文稿   簡報
 激光 鐳射
@@ -241,6 +259,7 @@ SQL注入攻擊     SQL隱碼攻擊
 組件 元件
 綁定 繫結
 網上鄰居   網路上的芳鄰
+網卡 網絡卡
 網吧 網咖
 網絡 網路
 網關 閘道器
@@ -255,6 +274,7 @@ SQL注入攻擊     SQL隱碼攻擊
 聯繫 聯絡
 聯繫歷史   通話記錄
 聲卡 音效卡
+聲明 宣告
 脫機 離線
 腳本 指令碼
 自動轉屏   自動旋轉螢幕
@@ -266,7 +286,7 @@ SQL注入攻擊     SQL隱碼攻擊
 藍牙 藍芽
 虛函數      虛擬函式
 虛擬機      虛擬機器
-表達式      表示式
+表達式      表示式 運算式
 複印 影印
 複選按鈕   覈取按鈕
 複選框      覈取方塊
@@ -288,16 +308,19 @@ SQL注入攻擊   SQL隱碼攻擊
 調用 呼叫
 調色板      調色盤
 調製解調器        數據機
-調試 偵錯
+調試 除錯 偵錯
 調試器      偵錯程式
 變量 變數
 軟件 軟體
 軟驅 軟碟機
 通信 通訊
 通訊卡      通話卡
+通配符      萬用字元
 連接 連線
+連接器      聯結器
 進制 進位制
 進程 程序 進程
+運算符      運算子
 運行 執行
 過程式編程        程序式程式設計
 遞歸 遞迴
@@ -327,9 +350,12 @@ SQL注入攻擊    SQL隱碼攻擊
 音頻 音訊
 頁眉 頁首
 頁腳 頁尾
+項目 專案
+預處理器   前處理器
 頭文件      標頭檔案
 頻分多址   分頻多重進接
 頻分複用   分頻多工
+類型 型別
 類模板      類别範本
 顯像管      映象管
 顯卡 顯示卡
@@ -347,4 +373,3 @@ SQL注入攻擊     SQL隱碼攻擊
 默認值      預設值
 點擊 點選
 鼠標 滑鼠
-比特幣      比特幣
index 20c7ec57b132ba1581c2d38f8bf6bb937d1d4771..6b0b3b6a0f53224b778bfaca567c5af847660123 100644 (file)
@@ -71,6 +71,7 @@
 肯尼亞      肯亞
 莫桑比克   莫三比克
 萊索托      賴索托
+萬象 永珍
 蘇里南      蘇利南
 貝寧 貝南
 贊比亞      尚比亞
index 4953bbb7f4f4cb6cad59bf2d026ed0c1d66a54cf..28ada276718e4e36d8efd1b9669fb4155407baa5 100755 (executable)
@@ -5,7 +5,7 @@ from common import find_target_items
 
 if len(sys.argv) != 3:
   print("Find the value keyword in all pairs")
-  print("Usage: ", sys.argv[0], "[input] [keyword]")
+  print(("Usage: ", sys.argv[0], "[input] [keyword]"))
   exit(1)
 
 find_target_items(sys.argv[1], sys.argv[2])
index fcbe588e8df7856124002f8debc3cd6467910c10..170bf60c02da6e983f985d1420f3e1153503669f 100755 (executable)
@@ -6,7 +6,7 @@ from common import sort_items
 
 if len(sys.argv) < 4:
   print("Merge and sort all text dictionaries")
-  print("Usage: ", sys.argv[0], "[input1] [input2] ... [inputN] [output]")
+  print(("Usage: ", sys.argv[0], "[input1] [input2] ... [inputN] [output]"))
   exit(1)
 
 all_lines = []
index 2d2d77f9a9d3a280d334efcc8fc0033025b0749d..f7024605869dd7788905637cfccaa41707efb6c3 100755 (executable)
@@ -5,7 +5,7 @@ from common import reverse_items
 
 if len(sys.argv) != 3:
   print("Reverse key and value of all pairs")
-  print("Usage: ", sys.argv[0], "[input] [output]")
+  print(("Usage: ", sys.argv[0], "[input] [output]"))
   exit(1)
 
 reverse_items(sys.argv[1], sys.argv[2])
index fb5f5adb0f159e748417e0ddcdbd8c4b2a1ef8fa..8268bde8117ae9b2a7aac3ccdd6a85f81ccf3dee 100755 (executable)
@@ -5,7 +5,7 @@ from common import sort_items
 
 if len(sys.argv) < 2:
   print("Sort the dictionary")
-  print("Usage: ", sys.argv[0], "[input] ([output])")
+  print(("Usage: ", sys.argv[0], "[input] ([output])"))
   exit(1)
 
 input = sys.argv[1]
index 0f6614a8de9aaabc308d494848be5ddd5ca73dc9..0cecdaa5ba793c57691e4051d0c453e5e145e0f1 100755 (executable)
@@ -6,7 +6,7 @@ from common import sort_items
 
 if len(sys.argv) < 2:
   print("Sort the dictionary")
-  print("Usage: ", sys.argv[0], "[directory]")
+  print(("Usage: ", sys.argv[0], "[directory]"))
   exit(1)
 
 dirtectory = sys.argv[1]
index 4fc18c3a59b5d4f547e0c05d9c6047995a3b8db5..7ae6bfa0b3dd9f94e1a399f6a2358d08dc73ca3b 100644 (file)
@@ -1,25 +1,22 @@
 #include <iostream>
-#include <node.h>
-#include <v8.h>
 #include <nan.h>
 
 #include "Config.hpp"
 #include "Converter.hpp"
 
-using namespace v8;
 using namespace opencc;
 
-string ToUtf8String(const Local<String>& str) {
-  v8::String::Utf8Value utf8(str);
-  return std::string(*utf8);
+string ToUtf8String(const v8::Local<v8::Value>& val) {
+  Nan::Utf8String utf8(val);
+  return string(*utf8);
 }
 
-class OpenccBinding : public node::ObjectWrap {
+class OpenccBinding : public Nan::ObjectWrap {
   struct ConvertRequest {
     OpenccBinding* instance;
     string input;
     string output;
-    Persistent<Function> callback;
+    Nan::Callback *callback;
     Optional<opencc::Exception> ex;
 
     ConvertRequest()
@@ -42,42 +39,40 @@ class OpenccBinding : public node::ObjectWrap {
   }
 
   static NAN_METHOD(New) {
-    NanScope();
     OpenccBinding* instance;
 
     try {
-      if (args.Length() >= 1 && args[0]->IsString()) {
-        string configFile = ToUtf8String(args[0]->ToString());
+      if (info.Length() >= 1 && info[0]->IsString()) {
+        string configFile = ToUtf8String(info[0]);
         instance = new OpenccBinding(configFile);
       } else {
         instance = new OpenccBinding("s2t.json");
       }
     } catch (opencc::Exception& e) {
-      NanThrowError(e.what());
-      NanReturnUndefined();
+      Nan::ThrowError(e.what());
+      return;
     }
 
-    instance->Wrap(args.This());
-    NanReturnValue(args.This());
+    instance->Wrap(info.This());
+    info.GetReturnValue().Set(info.This());
   }
 
   static NAN_METHOD(Convert) {
-    NanScope();
-    if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsFunction()) {
-      NanThrowTypeError("Wrong arguments");
-      NanReturnUndefined();
+    if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
+      Nan::ThrowTypeError("Wrong arguments");
+      return;
     }
 
     ConvertRequest* conv_data = new ConvertRequest;
-    conv_data->instance = ObjectWrap::Unwrap<OpenccBinding>(args.This());
-    conv_data->input = ToUtf8String(args[0]->ToString());
-    NanAssignPersistent(conv_data->callback, Local<Function>::Cast(args[1]));
+    conv_data->instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
+    conv_data->input = ToUtf8String(info[0]);
+    conv_data->callback = new Nan::Callback(info[1].As<v8::Function>());
     conv_data->ex = Optional<opencc::Exception>::Null();
     uv_work_t* req = new uv_work_t;
     req->data = conv_data;
     uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert);
 
-    NanReturnUndefined();
+    return;
   }
 
   static void DoConvert(uv_work_t* req) {
@@ -91,61 +86,56 @@ class OpenccBinding : public node::ObjectWrap {
   }
 
   static void AfterConvert(uv_work_t* req) {
-    NanScope();
+    Nan::HandleScope scope;
     ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
-    Local<Value> err = NanUndefined();
-    Local<String> converted = NanNew<String>(conv_data->output.c_str());
+    v8::Local<v8::Value> err = Nan::Undefined();
+    v8::Local<v8::String> converted = Nan::New(conv_data->output.c_str()).ToLocalChecked();
     if (!conv_data->ex.IsNull()) {
-      err = NanNew<String>(conv_data->ex.Get().what());
+      err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked();
     }
     const unsigned argc = 2;
-    Local<Value> argv[argc] = {
+    v8::Local<v8::Value> argv[argc] = {
       err,
-      NanNew(converted)
+      converted
     };
-    NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(conv_data->callback), argc, argv);
+    conv_data->callback->Call(argc, argv);
     delete conv_data;
     delete req;
   }
 
   static NAN_METHOD(ConvertSync) {
-    NanScope();
-    if (args.Length() < 1 || !args[0]->IsString()) {
-      NanThrowTypeError("Wrong arguments");
-      NanReturnUndefined();
+    if (info.Length() < 1 || !info[0]->IsString()) {
+      Nan::ThrowTypeError("Wrong arguments");
+      return;
     }
 
-    OpenccBinding* instance = ObjectWrap::Unwrap<OpenccBinding>(args.This());
+    OpenccBinding* instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
 
-    string input = ToUtf8String(args[0]->ToString());
+    string input = ToUtf8String(info[0]);
     string output;
     try {
       output = instance->Convert(input);
     } catch (opencc::Exception& e) {
-      NanThrowError(e.what());
-      NanReturnUndefined();
+      Nan::ThrowError(e.what());
+      return;
     }
 
-    Local<String> converted = NanNew<String>(output.c_str());
-    NanReturnValue(converted);
+    v8::Local<v8::String> converted = Nan::New(output.c_str()).ToLocalChecked();
+    info.GetReturnValue().Set(converted);
   }
 
-  static void init(Handle<Object> target) {
-    NanScope();
+  static NAN_MODULE_INIT(Init) {
     // Prepare constructor template
-    Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(OpenccBinding::New);
-    tpl->SetClassName(NanNew<String>("Opencc"));
+    v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(OpenccBinding::New);
+    tpl->SetClassName(Nan::New("Opencc").ToLocalChecked());
     tpl->InstanceTemplate()->SetInternalFieldCount(1);
     // Prototype
-    NODE_SET_PROTOTYPE_METHOD(tpl, "convert", Convert);
-    NODE_SET_PROTOTYPE_METHOD(tpl, "convertSync", ConvertSync);
+    Nan::SetPrototypeMethod(tpl, "convert", Convert);
+    Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync);
     // Constructor
-    target->Set(NanNew<String>("Opencc"), tpl->GetFunction());
+    v8::Local<v8::Function> cons = Nan::GetFunction(tpl).ToLocalChecked();
+    Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons);
   }
 };
 
-void init(Handle<Object> target) {
-  OpenccBinding::init(target);
-}
-
-NODE_MODULE(binding, init);
+NODE_MODULE(binding, OpenccBinding::Init);
index e20ee6dd0cb1fda4f4e63cb6d30bc5c3907d6ed7..433f1b7e2db913b9ff67d862a0b852d45253c13b 100644 (file)
@@ -1,6 +1,6 @@
 {
   "variables": {
-    "opencc_version": "1.0.3"
+    "opencc_version": "1.0.4"
   },
   "target_defaults": {
     "defines": [
index 2895a541480682d7ad9a83427691bfec8c59adfe..f5457984c6ad022012115e841bd6221a34f92b0a 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "opencc",
-  "version": "1.0.3",
+  "version": "1.0.4",
   "description": "Conversion between Traditional and Simplified Chinese",
   "author": "BYVoid <byvoid@byvoid.com>",
   "license": "Apache",
@@ -24,9 +24,9 @@
     "Traditional Chinese"
   ],
   "devDependencies": {
-    "mocha": "1.8.1"
+    "mocha": "2.2.5"
   },
   "dependencies": {
-    "nan": "^1.6.2"
+    "nan": "^2.2.0"
   }
 }
index cab6eff362bd7a07c8d7942de19c6c1b7ae504ce..35bc89be7e97ea0cbd0579cf694bb7175df98f0d 100644 (file)
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+#include <unordered_map>
+
 #include "Config.hpp"
 #include "ConversionChain.hpp"
 #include "Converter.hpp"
@@ -26,8 +28,6 @@
 
 #include "document.h"
 
-#include <unordered_map>
-
 using namespace opencc;
 
 typedef rapidjson::GenericValue<rapidjson::UTF8<char>> JSONValue;
@@ -168,19 +168,19 @@ public:
     std::ifstream ifs;
 
     // Working directory
-    ifs.open(fileName.c_str());
+    ifs.open(UTF8Util::GetPlatformString(fileName).c_str());
     if (ifs.is_open()) {
       return fileName;
     }
     // Package data directory
     if (PACKAGE_DATA_DIRECTORY != "") {
       string prefixedFileName = PACKAGE_DATA_DIRECTORY + fileName;
-      ifs.open(prefixedFileName.c_str());
+      ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str());
       if (ifs.is_open()) {
         return prefixedFileName;
       }
       prefixedFileName += ".json";
-      ifs.open(prefixedFileName.c_str());
+      ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str());
       if (ifs.is_open()) {
         return prefixedFileName;
       }
@@ -197,7 +197,7 @@ Config::~Config() { delete (ConfigInternal*)internal; }
 ConverterPtr Config::NewFromFile(const string& fileName) {
   ConfigInternal* impl = (ConfigInternal*)internal;
   string prefixedFileName = impl->FindConfigFile(fileName);
-  std::ifstream ifs(prefixedFileName);
+  std::ifstream ifs(UTF8Util::GetPlatformString(prefixedFileName));
   string content(std::istreambuf_iterator<char>(ifs),
                  (std::istreambuf_iterator<char>()));
 
index f0d52b0f926b94198a32edf3929b8f19fb9f29af..a02e53e62f0d72e8b5504e19764b8b6e55876441 100644 (file)
@@ -47,7 +47,15 @@ public:
   template <typename DICT>
   static bool TryLoadFromFile(const string& fileName,
                               std::shared_ptr<DICT>* dict) {
-    FILE* fp = fopen(fileName.c_str(), "rb");
+      FILE* fp =
+#ifdef _MSC_VER
+          // well, the 'GetPlatformString' shall return a 'wstring'
+          _wfopen(UTF8Util::GetPlatformString(fileName).c_str(), L"rb")
+#else
+          fopen(UTF8Util::GetPlatformString(fileName).c_str(), "rb")
+#endif // _MSC_VER
+          ;
+
     if (fp == NULL) {
       return false;
     }
index 90f412b412019371627053922c53c2c21b2b1b50..b3dfb6000dfad190259df1bda13ac0f1ddc89fa4 100644 (file)
  * limitations under the License.
  */
 
+#ifdef _MSC_VER
+#define NOMINMAX
+#include <Windows.h>
+#undef NOMINMAX
+#endif // _MSC_VER
+
 #include "Config.hpp"
 #include "Converter.hpp"
 #include "opencc.h"
@@ -82,7 +88,7 @@ size_t SimpleConverter::Convert(const char* input, size_t length,
 
 static string cError;
 
-opencc_t opencc_open(const char* configFileName) {
+opencc_t opencc_open_internal(const char* configFileName) {
   try {
     if (configFileName == nullptr) {
       configFileName = OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD;
@@ -95,6 +101,37 @@ opencc_t opencc_open(const char* configFileName) {
   }
 }
 
+#ifdef _MSC_VER
+opencc_t opencc_open_w(const wchar_t* configFileName) {
+  try {
+    if (configFileName == nullptr) {
+      return opencc_open_internal(nullptr);
+    }
+    std::string utf8fn = UTF8Util::U16ToU8(configFileName);
+    return opencc_open_internal(utf8fn.c_str());
+  } catch (std::runtime_error& ex) {
+    cError = ex.what();
+    return reinterpret_cast<opencc_t>(-1);
+  }
+}
+opencc_t opencc_open(const char* configFileName) {
+  if (configFileName == nullptr) {
+    return opencc_open_internal(nullptr);
+  }
+  std::wstring wFileName;
+  int convcnt = MultiByteToWideChar(CP_ACP, 0, configFileName, -1, NULL, 0);
+  if (convcnt > 0) {
+    wFileName.resize(convcnt);
+    MultiByteToWideChar(CP_ACP, 0, configFileName, -1, &wFileName[0], convcnt);
+  }
+  return opencc_open_w(wFileName.c_str());
+}
+#else
+opencc_t opencc_open(const char* configFileName) {
+  return opencc_open_internal(configFileName);
+}
+#endif
+
 int opencc_close(opencc_t opencc) {
   try {
     SimpleConverter* instance = reinterpret_cast<SimpleConverter*>(opencc);
index a662290ddbf73c8bb0a95c6dc4a6dbf8e32fb54f..ea03dc015bb46df3a28cdd5361564cc9bc8d5b36 100644 (file)
 
 #pragma once
 
+#ifdef _MSC_VER
+#define NOMINMAX
+#include <Windows.h>
+#undef NOMINMAX
+#endif // _MSC_VER
+
 #include "Common.hpp"
 
 namespace opencc {
@@ -241,5 +247,38 @@ public:
       pstr = NextChar(pstr);
     }
   }
+
+#ifdef _MSC_VER
+  static std::wstring GetPlatformString(const std::string& str) {
+    return U8ToU16(str);
+  }
+#else
+  static std::string GetPlatformString(const std::string& str) {
+    return str;
+  }
+#endif // _MSC_VER
+
+
+#ifdef _MSC_VER
+  static std::string U16ToU8(const std::wstring& wstr) {
+    std::string ret;
+    int convcnt = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
+    if (convcnt > 0) {
+      ret.resize(convcnt);
+      WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), &ret[0], convcnt, NULL, NULL);
+    }
+    return ret;
+  }
+
+  static std::wstring U8ToU16(const std::string& str) {
+    std::wstring ret;
+    int convcnt = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
+    if (convcnt > 0) {
+      ret.resize(convcnt);
+      MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &ret[0], convcnt);
+    }
+    return ret;
+  }
+#endif // _MSC_VER
 };
 }
index f180ce2534ad2e5405f02fc0aa177cedc1e6ac04..21b90469ffecf2da95511d23fe663c3c4ae5d7cb 100644 (file)
@@ -71,6 +71,18 @@ typedef void* opencc_t;
 * @ingroup opencc_c_api
 */
 OPENCC_EXPORT opencc_t opencc_open(const char* configFileName);
+#ifdef _MSC_VER
+/**
+* Makes an instance of opencc (wide char / Unicode)
+*
+* @param configFileName Location of configuration file. If this is set to NULL,
+*                       OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD will be loaded.
+* @return            A description pointer of the newly allocated instance of
+*                    opencc. On error the return value will be (opencc_t) -1.
+* @ingroup opencc_c_api
+*/
+OPENCC_EXPORT opencc_t opencc_open_w(const wchar_t* configFileName);
+#endif /* _MSC_VER */
 
 /**
 * Destroys an instance of opencc